package com.zxy.supplier_system.server.entity

import jakarta.persistence.*
import java.io.Serializable
import java.math.BigDecimal

@Entity
@IdClass(DirectSaleOrderItem.UnionId::class)
class DirectSaleOrderItem {

    data class UnionId(
        var order:Int? = null,
        var goods:Int? = null
    ):Serializable

    @Id
    @ManyToOne(optional = false)
    @JoinColumn
    lateinit var goods: Goods

    @Id
    @ManyToOne(optional = false)
    @JoinColumn
    lateinit var order: DirectSaleOrder

    @Column(nullable = false)
    lateinit var price: BigDecimal

    var amount: Int = 1

    var sequence: Int = 0

}

val List<DirectSaleOrderItem>.nextSequence: Int
    get() = this.maxOfOrNull {
        it.sequence
    }?.plus(1)?:0